function getRealCode(num, showHex) {
    if(num < 0) {
        let n = -num;
        n--;
        let str = '11111111111111111111111111111111'.concat(n.toString(2).split('').map(i => i & 1 ? 0 : 1).join('')).slice(-32);
        if(showHex) {
            return parseInt(str, 2);
        } else {
            return str;
        }
    } else { //
        if(showHex) {
            return num;
        } else {
            return num.toString(2);
        }
    }
}


function makeTable() { //列出单元可能的情况2^8和h`的结果
	var c, table = [];
	for (var n = 0; n < 256; n++) {
		c = n;
		for (var k = 0; k < 8; k++) {
			c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
		}
		table[n] = c;
	}
	return table;
}
var crcTable = makeTable();

function crc32str(crc, str, len, pos) {
	var t = crcTable,
		end = pos + len;
	// crc = crc ^ (-1);
	for (var i = pos; i < end; i++) {        
		crc = (crc >>> 8) ^ t[(crc ^ str[i]) & 0xFF];
	}
	crc = getRealCode((crc ^ (-1)), true)
	return (crc);
}

//将这些方法暴露出去
export {
	crc32str,
};
